/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elaborate.tag_analysis.client.actions;

import elaborate.tag_analysis.client.actions.reachability.ConnectedClustersGenerator;
import elaborate.tag_analysis.client.actions.ui.MultipleFileSelectionPanel;
import elaborate.tag_analysis.client.actions.ui.ReachabilityCalcDialog;
import elaborate.task.Task;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.io.*;

/**
 *
 * @author lendle
 */
public class GenerateConnectedClustersActionHandler extends BaseActionHandler {
    @Override
    protected void asyncHandleAction(ActionEvent event) {
        try {
            final ReachabilityCalcDialog dlg=new ReachabilityCalcDialog((Frame)context.getMainFrame(), true);
            dlg.setLocationRelativeTo(context.getMainFrame());
            dlg.setVisible(true);
            if(dlg.isOk()){
                final MultipleFileSelectionPanel fileSelector=dlg.getFileSelector();
                context.executeTask(new Task(){

                    @Override
                    public Object run() throws Exception {
                        File csv=fileSelector.getSelectedFile("csv");
                        File prefix=fileSelector.getSelectedFile("output");
                        ConnectedClustersGenerator generator=new ConnectedClustersGenerator();
                        generator.generate(csv, prefix, dlg.getThreshold());
                        return null;
                    }
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
